package com.mogu.blogs.service.impl;

import com.mogu.blogs.mapper.BlogContentMapper;
import com.mogu.blogs.service.BlogContentService;
import com.mogu.entity.TBlog;
import com.mogu.utils.RedisUtil;
import com.mogu.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author muxiaofeng
 * @Date 2020/6/10 19:26.
 */
@Service
public class BlogContentServiceImpl implements BlogContentService {

    @Autowired
    BlogContentMapper blogContentMapper;

    @Autowired
    RedisUtil redisUtil;

    @Override
    public TBlog getBlogByUid(String uid) {
        return blogContentMapper.getBlogByUid(uid);
    }

    @Override
    public Integer getBlogPraiseCountByUid(String uid) {

        Integer pariseCount = 0;
        if (StringUtils.isEmpty(uid)){
            return pariseCount;
        }
        String pariseJsonResult = redisUtil.get(uid);
        if (!StringUtils.isEmpty(pariseJsonResult)){
            pariseCount = Integer.parseInt(pariseJsonResult);
        }
        return pariseCount;
    }

    @Override
    public String praiseBlogByUid(String uid) {
        return null;
    }
}
